home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4924 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.0 KB  |  75 lines

  1. Path: scream.ing.com!news
  2. From: "John C. Lund" <jlund@allaire.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Delphi calling a C++ DLL; Help needed
  5. Date: Thu, 01 Feb 1996 11:05:17 -0600
  6. Organization: Allaire
  7. Message-ID: <3110F2CD.5287@allaire.com>
  8. NNTP-Posting-Host: 206.144.133.15
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b6a (Win95; I)
  13.  
  14. How can I use C++ DLLs to work with Delphi apps?
  15.  
  16. I've written a simple Delphi program that calls a function in a C++ DLL 
  17. I wrote. The DLL uses a "C" interface that I can call from other 
  18. environments (like VB and C++). Although I can call the DLL function 
  19. from my Delphi app, the parameters passed are garbage. I tried the same 
  20. declarations I found in the Delphi libraries, but to no avail.
  21.  
  22. For whatever reason it looks like the parameters are pushed and popped 
  23. from the stack differently beween environments.  I've tried declaring 
  24. the function in Delphi with "stdcall", "cdecl", and "pascal". 
  25.  
  26. The parameters expected by the DLL are all LPSTR (i.e. char*), so I've 
  27. tried passing PChar and an array of Char. 
  28.  
  29. Any suggestions?
  30.  
  31.  
  32. ***************
  33. Delphi SNIPPETS
  34. ***************
  35.  
  36. {type, private}
  37. function GetFieldsForTable(
  38.    pcharDataSourceName,
  39.    pcharUsername,
  40.    pcharPassword,
  41.    pcharTableName: pChar
  42.    ): integer;
  43.  
  44. {implementation}
  45. function TODBCInformant.GetFieldsForTable;
  46.    external 'patrik.dll' name 'GetFieldsForTable';
  47.  
  48. {I call the function like this:}
  49. nIndex:= GetFieldsForTable(strpcopy(pcharBuiffer,'Test'),
  50.    strpcopy(pcharBuiffer,''),
  51.    strpcopy(pcharBuiffer,''),
  52.    strpcopy(pcharBuiffer,'Employees'));
  53.  
  54.  
  55. ************
  56. C++ SNIPPETS
  57. ************
  58.  
  59. // My C++ header (.H) declares the prototype like this:
  60. extern "C" INT FAR PASCAL EXPORT GetFieldsForTable(
  61.    LPSTR lpszDataSourceName,
  62.    LPSTR lpszUsername,
  63.    LPSTR lpszPassword,
  64.    LPSTR lpszTableName
  65.    );
  66.  
  67. /*
  68. My implementation uses the same format, and the function is named in the 
  69. exports section of the .DEF file.
  70. */
  71.  
  72.  
  73. -- 
  74. // John C. Lund  jlund@allaire.com  http//:www.allaire.com/
  75.